c164a9
@@ -290,7 +290,7 @@
protected void initializeOp(Configuration hconf) throws HiveException {
         if (unionExprEval != null) {
           String[] names = parameters.get(j).getExprString().split("\\.");
           // parameters of the form : KEY.colx:t.coly
-          if (Utilities.ReduceField.KEY.name().equals(names[0])) {
+          if (Utilities.ReduceField.KEY.name().equals(names[0]) && names.length > 2) {
             String name = names[names.length - 2];
             int tag = Integer.parseInt(name.split("\\:")[1]);
             if (aggr.getDistinct()) {
@@ -314,7 +314,7 @@
protected void initializeOp(Configuration hconf) throws HiveException {
               }
             }
           } else {
-            // will be VALUE._COLx
+            // will be KEY._COLx or VALUE._COLx
             if (!nonDistinctAggrs.contains(i)) {
               nonDistinctAggrs.add(i);
             }
@@ -691,7 +691,7 @@
protected void updateAggregations(AggregationBuffer[] aggs, Object row,
         }
       }
 
-      // update non-distinct value aggregations: 'VALUE._colx'
+      // update non-distinct groupby key or value aggregations: 'KEY._COLx or VALUE._colx'
       // these aggregations should be updated only once.
       if (unionTag == 0) {
         for (int pos : nonDistinctAggrs) {
